package com.qf.attendance.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.attendance.qo.ApproveQO;
import com.qf.attendance.qo.TimeSheetQO;
import com.qf.attendance.qo.Update;
import com.qf.attendance.service.ApproveService;
import com.qf.attendance.service.TimeSheetService;
import com.qf.attendance.vo.ClocInVO;
import com.qf.attendance.vo.TimeSheetVO;
import com.qf.common.base.result.RespResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/attendance")
public class AttendanceController {

    @Resource
    private TimeSheetService timeSheetService;
    @Resource
    private ApproveService approveService;

    @ApiOperation("查询综合审批记录考勤信息")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<TimeSheetVO>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(timeSheetService.list(page, size));
    }

    @ApiOperation("查询打卡记录")
    @GetMapping("/clockIn")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<ClocInVO>> clockIn(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(timeSheetService.clockIn(page, size));
    }

    @ApiOperation("查询特定条件考勤信息")
    @PostMapping("/selectList")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数"), @ApiImplicitParam(name = "timeSheetQO", value = "查询条件对象")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<TimeSheetVO>> selectList(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, TimeSheetQO timeSheetQO) {
        return RespResult.success(timeSheetService.selectList(page, size, timeSheetQO));
    }

    @ApiOperation("添加考勤记录")
    @PostMapping("/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "timeSheetQO", value = "添加对象")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult insert(@RequestBody TimeSheetQO timeSheetQO) {
        return timeSheetService.insert(timeSheetQO);
    }

    @ApiOperation("修改考勤记录")
    @PostMapping("/update")
    @ApiImplicitParam(name = "update", value = "考勤记录对象")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult update(@RequestBody Update update) {
        return timeSheetService.update(update);
    }

    @ApiOperation("删除考勤记录")
    @GetMapping("/delete")
    @ApiImplicitParam(name = "timeSheetId", value = "考勤ID")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<ClocInVO>> delete(@RequestParam int timeSheetId) {
        return timeSheetService.delete(timeSheetId);
    }

    @ApiOperation("查询审批详情信息")
    @GetMapping("/select")
    @ApiImplicitParam(name = "timeSheetId", value = "考勤ID")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult select(@RequestParam int timeSheetId) {
        return RespResult.success(approveService.select(timeSheetId));
    }

    @ApiOperation("审批状态")
    @GetMapping("/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "approveId", value = "审批ID"), @ApiImplicitParam(name = "status", value = "状态")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult update(@RequestParam int approveId, @RequestParam int status) {
        return RespResult.success(approveService.update(approveId, status));
    }

    @ApiOperation("添加出差记录")
    @PostMapping("/insertApprove")
    @ApiImplicitParams({@ApiImplicitParam(name = "approveQO", value = "添加对象")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult insertApprove(@RequestBody ApproveQO approveQO) {
        return approveService.insert(approveQO);
    }

}
